/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ipercube.sample;

import com.ipercube.Column;
import com.ipercube.DataMap;
import com.ipercube.Measure;
import com.ipercube.Row;
import com.ipercube.impl.simple.SimpleMeasure;
import com.ipercube.model.AbstractMeasureEvaluator;
import com.ipercube.model.Record;
import java.util.List;

/**
 *
 * @author tartur
 */
public class SampleMeasureEvaluator extends AbstractMeasureEvaluator{

    @Override
    public Measure evaluate(DataMap dataMap, Row r, Column c) {
        Double value = null;
        List<Record> records = dataMap.getRecordsAt(r, c);
        if (records != null && !records.isEmpty()) {
            value = 0.0;
            for (Record record : records) {
                Double d = (Double) record.getValue(SampleDataModel.INCOME);
                value += d;
            }
        }
        SimpleMeasure measure = new SimpleMeasure(Double.class, value);
        return measure;
    }

    public Class<?> getMeasureType() {
        return Double.class;
    }

}
